/*
 * ------------------------------------------------------------------
 * 错误处理中间件
 * ------------------------------------------------------------------
 * @关于我：
 * QQ:2815473064
 * wechat:13531609457
 * ------------------------------------------------------------------
 */
module.exports = (err, req, res, next) => {
  let { code, msg, name, message, description, stack } = err;
  // fileName(Mozilla);
  // lineNumber(Mozilla);
  // columnNumber(Mozilla);
  // stack(Mozilla);
  // description(Microsoft);
  // number(Microsoft);
  console.log(err);
  let filePath = null

  try {
    filePath = stack.split("at")[1].split("(")[1].split(")")[0]
  } catch (error) {

  }
  code = code ?? 500
  msg = msg || message
  console.log("error 中间件==================");
  console.log({
    filePath,
    code, msg
  });
  console.log("==============================");
  let statusCode = err.status || err.statusCode || 500;
  delete err.statusCode;
  res.status(statusCode).send(err);
};
